<?php
    /**
     * Created by PhpStorm.
     * User: huangzhongwei
     * Date: 2018/10/26
     * Time: 16:33
     */

    namespace app\api\controller;

    use app\api\service\Pay as PayService;
    use app\api\validate\IDMustBePositiveInt;
    use app\api\service\WxNotify;
    use think\facade\Env;
    use think\facade\Log;

    require_once(Env::get('extend_path') . '/NewWxPay/WxPay.Api.php');
    require_once(Env::get('extend_path') . '/NewWxPay/WxPay.Config.php');


    class Pay extends BaseController
    {
        protected $config;

        function __construct()
        {
            $this->config = new \WxPayConfig();
        }

        protected $beforeActionList = [
            'checkExclusiveScope' => ['only' => 'getPreOrder'],
        ];

        public function getPreOrder($id = '')
        {
            (new IDMustBePositiveInt())->goCheck();
            $pay = new PayService($id);
            return $pay->pay();
        }

        public function receiveNotify()
        {


            //        获取微信返回的xml数据
            //         $xmlData = file_get_contents('php://input');
            //         Log::error($xmlData);
            //      	 error_log($xmlData,'fuck.log');
            //	     error_log($_REQUEST,'test.log');
            //检测库存量，超卖，更新status
            Log::record('成功进入');
            $notify = new WxNotify();
            $notify->handle($this->config);
            //    做一次转发，然后就可以进行断点调试了
            //        $xmlData = file_get_contents('php://input');
            //        $result = curl_post_raw('http:/zerg.cn/api/v1/pay/re_notify?XDEBUG_SESSION_START=13133',
            //            $xmlData);
            //        return $result;
            //        Log::error($xmlData);
        }


    }